<?php

declare(strict_types=1);

namespace App\CustHub\Model;

use Mine\MineModel;

/**
 * @property int $id 
 * @property int $invite_id 方案ID
 * @property int $robot_id 机器人
 * @property int $custom_total 客户数量
 * @property int $success_total 成功数量
 * @property int $fail_total 失败数量
 * @property int $complete_total 完成数量
 * @property int $status 0=等待中 1=发送中 2=成功 3=失败 4=暂停 5=取消
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property array $custom_ids 指定用户
 * @property-read null|ChRobot $robot 
 */
class ChCrowdInviteSubTask extends MineModel
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'ch_crowd_invite_sub_task';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'invite_id', 'robot_id', 'custom_total', 'success_total', 'fail_total', 'complete_total', 'status', 'created_at', 'updated_at', 'custom_ids'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'invite_id' => 'integer', 'robot_id' => 'integer', 'custom_total' => 'integer', 'success_total' => 'integer', 'fail_total' => 'integer', 'complete_total' => 'integer', 'status' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'custom_ids' => 'array'];

    public function robot()
    {
        return $this -> hasOne(ChRobot::class,'id','robot_id');
    }

    public static function saveSubTask($invite_id,$robot_id,$total,$custom_ids=null)
    {
        $model = new self();
        $model->invite_id=$invite_id;
        $model->robot_id=$robot_id;
        $model->custom_total=$total;
        $model->custom_ids=$custom_ids;
        $model->save();
    }
}
